package controllers;


import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import models.SolutionSubmission;
import models.Rating;

import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyService;
import com.googlecode.objectify.Query;


public class MyNominationsConnect {
	int iROWS;
	Boolean hasEntries;

	public List<HashMap<String, Object>> getQuery(String fieldName, String Value) {
		List<HashMap<String, Object>> objList = new LinkedList<HashMap<String, Object>>();
		Objectify ofy = ObjectifyService.begin();
		
		try {
									
			Query<Rating> q = ofy.query(Rating.class).filter(fieldName, Value);
			for (Rating f : q.fetch()) {
				HashMap<String, Object> itemMap = new HashMap<String, Object>();				
				itemMap.put("SolID", f.getSolID());
				itemMap.put("Year", f.getBestOfBestYear());
				itemMap.put("Month", f.getBestOfBestMonth());				
				hasEntries = true;		
				
				try{
					Query<SolutionSubmission> a = ofy.query(SolutionSubmission.class).filter("SolID", f.getSolID());
					for (SolutionSubmission fe : a.fetch()) {					
						itemMap.put("Location", fe.getLocation());
						itemMap.put("Customer", fe.getCustomer());
						hasEntries = true;
					}
				}catch (Exception e) {
					e.printStackTrace();
				}
				objList.add(itemMap);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		return objList;
	}

}
